<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>在原生HTML中使用Vue.js</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        body {
            /*background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);*/
            color: #333;
            min-height: 100vh;
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .container {
            max-width: 800px;
            width: 100%;
            background-color: white;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            overflow: hidden;
        }
        header {
            background: linear-gradient(90deg, #4b6cb7 0%, #182848 100%);
            color: white;
            padding: 25px;
            text-align: center;
        }
        header h1 {
            font-size: 2.2rem;
            margin-bottom: 10px;
        }
        header p {
            opacity: 0.9;
            font-size: 1.1rem;
        }
        .content {
            padding: 25px;
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 25px;
        }
        @media (max-width: 768px) {
            .content {
                grid-template-columns: 1fr;
            }
        }
        .card {
            background: #f8f9fa;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
            border-left: 4px solid #4b6cb7;
        }
        .card h2 {
            color: #2c3e50;
            margin-bottom: 15px;
            font-size: 1.4rem;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: 500;
            color: #2c3e50;
        }
        input, select {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1rem;
            transition: border 0.3s;
        }
        input:focus, select:focus {
            border-color: #4b6cb7;
            outline: none;
            box-shadow: 0 0 0 2px rgba(75, 108, 183, 0.2);
        }
        button {
            background: #4b6cb7;
            color: white;
            border: none;
            padding: 10px 15px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1rem;
            transition: background 0.3s;
            width: 100%;
        }
        button:hover {
            background: #3a5999;
        }
        .result {
            margin-top: 15px;
            padding: 15px;
            background: #e8f4fd;
            border-radius: 5px;
            border-left: 4px solid #2196F3;
        }
        .result h3 {
            margin-bottom: 10px;
            color: #2c3e50;
        }
        .list-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 0;
            border-bottom: 1px solid #eee;
        }
        .list-item:last-child {
            border-bottom: none;
        }
        .remove-btn {
            background: #e74c3c;
            color: white;
            border: none;
            padding: 5px 10px;
            border-radius: 3px;
            cursor: pointer;
            font-size: 0.8rem;
            width: auto;
        }
        .remove-btn:hover {
            background: #c0392b;
        }
        .highlight {
            background-color: #fffacd;
            padding: 2px 4px;
            border-radius: 3px;
        }
        footer {
            text-align: center;
            padding: 20px;
            background: #f1f1f1;
            color: #666;
            font-size: 0.9rem;
        }
    </style>
</head>
<body>
<div id="app" class="container">
    <header>
        <h1>在原生HTML中使用Vue.js</h1>
        <p>无需构建工具，直接在HTML中使用Vue.js的响应式功能</p>
    </header>

    <div class="content">
        <div class="card">
            <h2>数据绑定示例</h2>
            <div class="form-group">
                <label for="name">请输入您的姓名：</label>
                <input type="text" id="name" v-model="name" placeholder="输入姓名">
            </div>
            <div class="form-group">
                <label for="age">请选择您的年龄：</label>
                <select id="age" v-model="age">
                    <option value="" disabled selected>选择年龄</option>
                    <option v-for="n in 10" :value="n+17">{{ n+17 }} 岁</option>
                </select>
            </div>
            <div class="result">
                <h3>绑定结果：</h3>
                <p>您好，<span class="highlight">{{ name || '未知用户' }}</span>！</p>
                <p v-if="age">您选择的年龄是：<span class="highlight">{{ age }} 岁</span></p>
                <p v-else>请选择您的年龄</p>
            </div>
        </div>

        <div class="card">
            <h2>列表渲染与事件处理</h2>
            <div class="form-group">
                <label for="newItem">添加新项目：</label>
                <input type="text" id="newItem" v-model="newItem" placeholder="输入项目名称" @keyup.enter="addItem">
            </div>
            <button @click="addItem">添加项目</button>

            <div class="result">
                <h3>项目列表：</h3>
                <div v-if="items.length">
                    <div class="list-item" v-for="(item, index) in items" :key="index">
                        <span>{{ index + 1 }}. {{ item }}</span>
                        <button class="remove-btn" @click="removeItem(index)">删除</button>
                    </div>
                </div>
                <p v-else>暂无项目，请添加</p>
            </div>
        </div>
    </div>

    <footer>
        <p>此示例展示了如何在原生HTML中使用Vue.js的响应式数据绑定、条件渲染、列表渲染和事件处理功能</p>
    </footer>
</div>

<script>
    const { createApp } = Vue;

    createApp({
        data() {
            return {
                name: '',
                age: '',
                newItem: '',
                items: ['Vue.js 数据绑定', 'Vue.js 条件渲染', 'Vue.js 列表渲染']
            }
        },
        methods: {
            addItem() {
                if (this.newItem.trim()) {
                    this.items.push(this.newItem);
                    this.newItem = '';
                }
            },
            removeItem(index) {
                this.items.splice(index, 1);
            }
        }
    }).mount('#app');
</script>
</body>
</html>